Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1545 without dos and stats cleanups #2046

Merged
merged 322 commits into from
Jan 8, 2025

Conversation

kladkogex
Copy link
Collaborator

@kladkogex kladkogex commented Nov 25, 2024

State locking/ performance improvements for SKALEd.

  1. Use LevedlDB read-only snaps for all read-only JSON-RPC calls

In the past we had to constantly lock/unlock LevelDB state because it was used both during block processing
(write access) and JSON-RPC calls (read access)

Now we use the actual LevelDB only during block processing, so we do not need to lock it, since LevelDB will always be used by a single thread.

For read-only calls through JSON-RPC we use snapshots created at the end of each block.
This significantly improved performance and made calls much simpler, because we do not do state locking anymore.

image

Added SnapshotManager class that manages snapshots and closes them once they are not used anymore.

Since we already have a feature to reopen LevelDB during execution, added mechanics to close anbd reopen snapshot objects during reopen of the database (if you want to close database handle, the snapshot objects created for this handle need to be closed first)

  1. Simplified pending queue/broadcast and removed unnecessary locks.

Now when a new transaction comes from JSON-RPC it is immediately broadcast to other nodes and added to the pending queue. Previously a transaction would not be added to the blockproposal until it was broadcast, which was making things unnecessary complex and delaying transaction inclusion in the block.

  1. Increased default ZMQ outgoing queue size to 1024 transactions.

It was only 16 transactions before, which caused the queue to overfill and lose transactions during broadcast.

  1. Removed unnecessary transaction cache on transaction arrival. The cash did not improve performance but caused high memory consumption and memory leaks because it was never cleaned.

  2. Fixed a bug in partial catchup receipts storage, which caused large blocks processing to stuck for seconds and also could process the same block twice. Now for each transaction once it is processed the receipt is immediately written to LevelDB. If there is a crash and restart, only the unprocessed transactions in the block are processed. Added a test for partial catchup (previously there was no test)

  3. Added a set of parallel performance tests to test_eth that test ERC-20 token tranfers, native token transfers and all of major lots of JSON-RPC calls

  4. Changed m_rawData field in Transaction to shared pointer to speed up Transaction copying and save memory. Skaled copies Transaction objects all the time, shared pointer guarantees that copies do not consume additional memory.

  5. Did some small fixes to JSON-RPC API error handling to make it similar to Geth.

libethereum/ClientBase.h Show resolved Hide resolved
test/unittests/libweb3jsonrpc/jsonrpc.cpp Outdated Show resolved Hide resolved
test/unittests/libweb3jsonrpc/jsonrpc.cpp Outdated Show resolved Hide resolved
libskale/State.h Outdated Show resolved Hide resolved
libweb3jsonrpc/Eth.cpp Outdated Show resolved Hide resolved
test/unittests/libevm/VMTest.cpp Outdated Show resolved Hide resolved
test/unittests/libweb3jsonrpc/jsonrpc.cpp Outdated Show resolved Hide resolved
test/unittests/libweb3jsonrpc/jsonrpc.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@DmytroNazarenko DmytroNazarenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please specify where these scripts are used:

  • test/unittests/libweb3jsonrpc/process_memory_monitor.bash
  • test/unittests/libweb3jsonrpc/run_skaled.py
  • test/unittests/libweb3jsonrpc/contracts/compile.py

libethereum/ClientBase.h Show resolved Hide resolved
libethereum/TransactionQueue.cpp Show resolved Hide resolved
libskale/OverlayDB.cpp Outdated Show resolved Hide resolved
skaled/main.cpp Outdated Show resolved Hide resolved
skale-vm/main.cpp Outdated Show resolved Hide resolved
@@ -153,7 +153,7 @@ BOOST_AUTO_TEST_CASE( fillingExpectationOnSingleNetwork,
}


BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES( fillingWithWrongExpectation, 2 )
BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES( fillingWithWrongExpectation, 1 )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should this check be changed?

@DmytroNazarenko DmytroNazarenko merged commit 2d312e0 into v4.0.0 Jan 8, 2025
4 of 5 checks passed
@DmytroNazarenko DmytroNazarenko deleted the 1545_without_dos_and_stats_cleanups branch January 8, 2025 18:59
@github-actions github-actions bot locked and limited conversation to collaborators Jan 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cleanup state locking and make JSON RPC calls like eth_call faster
3 participants